import org.jsecurity.authc.UsernamePasswordToken
import org.jsecurity.authc.AuthenticationException
import rowingmanager.domain.User

class LoginService {

    boolean transactional = false

    def jsecSecurityManager

    User login (String email, String password){
       log.info("loginService")
       log.info("email: "+email+", password: "+password)
       def user = User.findByEmailAndPassword(email,password)
       if(user) println("Found user - Name: "+user.name)
       return user
    }

    boolean authenticate(email,password)
    {
        def authToken = new UsernamePasswordToken(email,password)
        try{
            this.jsecSecurityManager.login(authToken)
            return true
        }
        catch(AuthenticationException ex){
            return false
        }
    }
}
